
<?php
/**
 * 功能描述：
 * 1）实现经纪人注册
 * 2）注册URL 
 * 		base_url().'index.php/user_control/add'
 * 		eg:http://192.168.33.10/CI/index.php/user_control/add
 * 
 *  相关配置参数：
 *  _myconfig.php : $config['json_url_base']
 *  database.php
 *  config.php : $config['base_url']
 * 
 * 注意事项：
 * 1）方法体中如果包含了视图需要引用如下语句：
 * $this->load->helper('url');
 * 
 * 总结：
 * 1) add方法体中虽然引用了多个view，但是由于是在一个方法体中，所以很方便进行数据的传递，比如：注册第一步的表单数据通过
 * 验证后传递给第二步的view
 * 2) 关于接收post或get数据的小技巧
 * 		a)  空值处理 
 * 			$openId = isset($_POST['openId'])?$_POST['openId']:'';
 * 		b） 空值处理＋去空格 
 * 			$name = isset($_POST['name'])?str_replace(' ', '', $_POST['name']):'';
 * 
 * 
 */


if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_Control extends CI_Controller {


	// 注册经纪人
	public function add(){
		$this->load->helper('url');
		
		$this->config->load('_myconfig.php');
		$debug = $this->config->item('mydebug');
		$showdebug = $this->config->item('showdebug');
		$data['debug']=$debug;
		$data['showdebug']=$showdebug;
		
		$uid = isset($_POST['uid'])?$_POST['uid']:0;
		$openId = isset($_POST['openId'])?$_POST['openId']:'';
		$accessToken = isset($_POST['accessToken'])?$_POST['accessToken']:'';
		$created = isset($_POST['created'])?$_POST['name']:time();
		$province = isset($_POST['province'])?$_POST['province']:'';
		$city = isset($_POST['city'])?$_POST['city']:'';
		$area = isset($_POST['area'])?$_POST['area']:'';
		$provinceId = isset($_POST['provinceId'])?$_POST['provinceId']:'';
		$cityId = isset($_POST['cityId'])?$_POST['cityId']:'';
		$areaId = isset($_POST['areaId'])?$_POST['areaId']:'';
		$bankType = isset($_POST['bankType'])?$_POST['bankType']:0;
		$state = isset($_POST['state'])?$_POST['state']:0;
		$flag = isset($_POST['flag'])?$_POST['flag']:0;	// 1:为提交态
		
		$name = isset($_POST['name'])?str_replace(' ', '', $_POST['name']):'';
		$company = isset($_POST['company'])?str_replace(' ', '', $_POST['company']):'';
		$phone = isset($_POST['phone'])?str_replace(' ', '', $_POST['phone']):'';
		$idCard = isset($_POST['idCard'])?str_replace(' ', '', $_POST['idCard']):'';
		$bankNo = isset($_POST['bankNo'])?str_replace(' ', '', $_POST['bankNo']):'';
		
		
		
		str_replace(' ', '', $_POST['name']);
		
		
		
		$user = array("id"=>$uid,"openId"=>$openId,"accessToken"=>$accessToken,"name"=>$name,
				"created"=>$created,"company"=>$company,"phone"=>$phone,
				"province"=>$province,"city"=>$city,"area"=>$area,"idCard"=>$idCard,
				"provinceId"=>$provinceId,"cityId"=>$cityId,"areaId"=>$areaId,
				"bankType"=>$bankType,"bankNo"=>$bankNo,"state"=>$state);
		
		
// 		print_r($user);
		$data['title']='经纪人｜注册';
		
		$data['openId']=$openId;
		$data['flag']=$flag;
		$data['uid']=$uid;
		$data['user']=$user;
		
		if($flag==0){	
			print_r($data);
			$this->load->view('jjr/regist1',$data); // 注册一
		}
		
		if($flag==1){	// 注册一提交
// 			$this->load->model('user_model');
// 			$check_result = $this->user_model->check($user);
// 			$data['check_result']=$check_result;	// 验证
// 			print_r($check_result);
			
// 			$id = $this->user_model->add($user);  // 可以把第一步的数据传递到第二步的隐藏表单域中
// 			$user['id']=$id;
			print_r($data);
			$this->load->view('jjr/regist2',$data); // 注册二
			
		}
		
		if($flag==2){	// 注册到第二步
			$this->load->model('user_model');
			$id = $this->user_model->add($user);
// 			$user['id']=$id;
			
			$data['msg']="注册成功,请等待管理员审核";
			print_r($data);
			$this->load->view('jjr/_msg',$data);
		}
		
		
		
		
	}
	

	public function update(){
		$this->config->load('_myconfig.php');
		$debug = $this->config->item('mydebug');
		$showdebug = $this->config->item('showdebug');
		$data['debug']=$debug;
		$data['showdebug']=$showdebug;
		
		$this->load->model('j_client');
		$arr = array('usid'=>22,'uname'=>'deng222','upass'=>'1233333');
		$this->j_client->client_update(2,$arr);
	}

	public function delete(){
		$this->config->load('_myconfig.php');
		$debug = $this->config->item('mydebug');
		$showdebug = $this->config->item('showdebug');
		$data['debug']=$debug;
		$data['showdebug']=$showdebug;
		
		$this->load->model('j_client');
		$this->j_client->client_delete(22);
	}

	public function select()
	{
		$this->config->load('_myconfig.php');
		$debug = $this->config->item('mydebug');
		$showdebug = $this->config->item('showdebug');
		$data['debug']=$debug;
		$data['showdebug']=$showdebug;
		
		$this->load->model('j_client');
		$arr = $this->j_client->client_select(14);
		print_r($arr);
		echo $arr[0]->id;

	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */